const credentials = [
  {
    username: 'testuser1',
    password: 'test123456',
  },
  {
    username: 'testuser2',
    password: 'test123456',
  },
  {
    username: 'testuser3',
    password: 'test123456',
  },
  {
    username: 'testuser4',
    password: 'test123456',
  },
  {
    username: 'test1',
    password: '123456',
  },
]

const login = {
  url: '/mock/auth/login',
  method: 'post',
  response: (request) => {
    const { username, password } = request.body

    if (!username || !password) {
      return {
        status: 422,
        data: {},
        message: 'Account and password is required',
      }
    }

    if (!credentials.find((credential) => credential.username === username && credential.password === password)) {
      return {
        status: 401,
        data: {},
        message: 'Account or password is incorrect',
      }
    }
    return {
      status: 200,
      data: {
        access_token:
          'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c',
        refresh_token:
          'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c',
      },
      message: 'ok',
    }
  },
}

export default [login]
